﻿using AutoMapper;
using MediatR;
using Traceability.APP.Application.Command.Slaughters;
using Traceability.Damoin;
using Traceability.ErrorCode;
using Traceability.Infaseture;

namespace Traceability.APP.Application.CommandHadnLer.Slaughters
{
    public class UpdateSlaughterCommandHandLer : IRequestHandler<UpdateSlaughterCommand, APIResult<int>>
    {


        private readonly IBaseRepostiy<Slaughter> _slaughter;
        private readonly IMapper mapper;

        public UpdateSlaughterCommandHandLer(IBaseRepostiy<Slaughter> slaughter, IMapper mapper)
        {
            _slaughter = slaughter;
            this.mapper = mapper;
        }
        public async Task<APIResult<int>> Handle(UpdateSlaughterCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            var list = mapper.Map<Slaughter>(request);
            list.UpdateUserTime = DateTime.Now;
            var res = await _slaughter.Update(list);

            result.Code = ResultCode.Ok;
            result.Message = "养殖信息修改成功";
            result.Data = res;
            return await Task.FromResult(result);
        }
    }
}
